package {
	import de.wellenblau.objectGetter.PathTranslation;
	import de.wellenblau.objectGetter.imgGetter;
	import de.wellenblau.objectGetter.xmlGetter;
	import de.wellenblau.slideshow.FadeInOutSlideshow;
	import de.wellenblau.slideshow.MoveLeftSlideshow;
	
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.utils.getDefinitionByName;

	[SWF(backgroundColor="0xffffff", frameRate="30")]
	public dynamic class mySlideshow extends Sprite
	{		
		public function mySlideshow()
		{
			
			//config the stage 
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			
			//get the relative path from the params
			PathTranslation.flashVars = this.loaderInfo.parameters;			
			
			//get the xml file
			new xmlGetter(this,xmlHandle,PathTranslation.rel2abs("header.xml"));
		}
			
		public function xmlHandle(x:XML):void{
	
			//configurate the tweener
			var config:XMLList = x.elements("config");
			
			//reconfigure absulte path to image location
			PathTranslation.setAbsolutePath = config.imgpath.@path;
				
			//images
			var images:XMLList = x.elements("img");	
				
			//create slideshow by name
			this[config.slideshow.@name] = new (getDefinitionByName(config.slideshow.@type) as Class);
			//display the slideshow
			addChild(this[config.slideshow.@name]);	
			//config the slideshow
			this[config.slideshow.@name].tweenconfig = config.slideshow;
			//save the number of images	
			this[config.slideshow.@name].maxImages = images.length();
			
			//load each image
			for each(var image:String in images){
				new imgGetter(
					this[config.slideshow.@name], 			 	// callback class
					this[config.slideshow.@name]['addImage'] , 	// callback function
					PathTranslation.rel2abs(image) 				// imgPath
				);
			}
		}
		
		private function keepImports():void{
			FadeInOutSlideshow;	
			MoveLeftSlideshow;
		}
	}
}
